package cn.edu.xhu.library_management.book.controller;

import cn.edu.xhu.library_management.book.entity.LmBook;
import cn.edu.xhu.library_management.book.entity.LmReservation;
import cn.edu.xhu.library_management.book.entity.dto.BookRecordDTO;
import cn.edu.xhu.library_management.book.service.LmReservationService;
import cn.edu.xhu.library_management.common.entity.R;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: MMJ
 * @Date: 2023 - 04 - 19
 * @Description: 图书预约
 */
@Api(tags = "图书预约")
@ApiSort(3)
@RestController
@RequestMapping("/lm_book/reservation")
public class BookReservation {

    @Autowired
    private LmReservationService reservationService;
    /* minio 服务器地址 */
    @Value("${minio.server}")
    private String imgServer;
    @Value("${minio.port}")
    private int serverPort;

    @PostMapping
    @ApiOperation(value = "预约图书", produces = "application/json")
    @ApiOperationSupport(order = 221)
    public boolean reservation(@RequestBody LmReservation reservation){
        return reservationService.reservationBook(reservation);
    }
    @GetMapping
    @ApiOperation(value = "获取预约图书记录", produces = "application/json")
    public List<BookRecordDTO> getReservationBook(@RequestParam("userAccount") String userAccount){
        // 获取用户预约记录
        List<BookRecordDTO> books = reservationService.getReservationBook(userAccount);
        books.forEach(book -> book.setBoImage(imgServer + ":" + serverPort + book.getBoImage()));
        return books;
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除预约记录", produces = "application/json")
    public boolean delReservation(@PathVariable("id") Integer id){
        return reservationService.removeById(id);
    }


}
